<?php
declare(strict_types=1);

namespace App\Task;

use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Crontab\Annotation\Crontab;
use Hyperf\Di\Annotation\Inject;
use App\Service\PushService;
use Hyperf\DbConnection\Db;

/**
 * 提醒用户任务
 * 每分钟执行一次
 */
class NormalTask 
{
    #[Inject]
    private PushService $pushServ;

    /**
     * 执行方法
     * [execute description]
     * @return [type] [description]
     */
    public function execute()
    {
        $remind_time_st = strtotime(date("Y-m-d H:i:00"));
        $where = [
            ['is_del', '=', 0],
            ['status', '=', 1],
            ['is_push', '=', 0],
            ['remind_time', '=', $remind_time_st],
        ];
        // 每次查询的数量
        $chunkSize = 100;
        Db::table('user_sub')
            ->select(['id','user_id','std_id','remind_time'])
            ->where($where)
            ->orderBy('id')
            ->chunk($chunkSize, function ($datas) {
                $pushServ = $this->pushServ;
                foreach ($datas as $data) {
                    go(function() use ($pushServ,$data){
                        $pushServ->doPush($data);
                    });
                }
            });
    }
}
